<template>
    <div class="manage-cloud-service">
        <div style="height: 35px">
            <el-form :model="searchForm" :inline="true" size="mini">
                <el-form-item label="name">
                    <el-input v-model="searchForm.name"></el-input>
                </el-form-item>
                <el-form-item label="code">
                    <el-input v-model="searchForm.code"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="listCloudService">Search</el-button>
                    <el-button type="primary" @click="listCloudService">Refresh</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-table
                border
                default-expand-all
                highlight-current-row
                :data="cloudServiceTable"
                row-key="name"
                height="500"
                size="mini"
                style="width: 100%">
            <el-table-column
                    prop="name"
                    label="name"
                    width="*">
            </el-table-column>
            <el-table-column
                    prop="serviceId"
                    label="serviceId"
                    width="200">
            </el-table-column>
            <el-table-column
                    prop="instanceId"
                    label="instanceId"
                    width="300">
            </el-table-column>
            <el-table-column
                    prop="status"
                    label="status"
                    width="140">
            </el-table-column>
            <el-table-column
                    label="操作"
                    width="252">
                <template slot-scope="scope">
                    <div v-if="scope.row.instanceId !== undefined">
                        <el-button
                                v-if="scope.row.status !== 'UP'"
                                size="mini"
                                @click="handleOffLine(scope.row.serviceId, scope.row.instanceId, 'UP')">上线
                        </el-button>
                        <el-button
                                v-if="scope.row.status === 'UP'"
                                size="mini"
                                @click="handleOffLine(scope.row.serviceId, scope.row.instanceId, 'OUT_OF_SERVICE')">下线
                        </el-button>
                        <el-button
                                :disabled="scope.row.status !== 'OUT_OF_SERVICE'"
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.row.serviceId, scope.row.instanceId)">删除
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>

  import {listCloudService, updateCloudServiceStatus} from "../../../../api/manage/cloud/service";

  export default {
    name: "CloudService",
    data () {
      return {
        showCloudServiceForm: false,
        showCloudServiceItemForm: false,
        cloudServiceTable: [],
        searchForm: {},
        cloudServiceForm: {},
        cloudServiceItemForm: {}
      }
    },
    methods: {
      handleOffLine (appId, instanceId, status) {
        updateCloudServiceStatus(appId, instanceId, status).then(result => {
          this.listCloudService()
        })
      },
      listCloudService () {
        listCloudService().then(result => {
          this.cloudServiceTable = result.data.cloudServices
        })
      }
    },
    created () {
      this.listCloudService()
    }
  }
</script>

<style scoped>
    .manage-cloud-service {
        width: 100%;
        height: 100%;
    }

    /* element ui样式重写 */
    .manage-cloud-service > .el-table {
        height: calc(100% - 35px) !important;
    }

    .manage-cloud-service > .el-table > .el-table__body-wrapper {
        height: calc(100% - 35px) !important;
    }
</style>